#!/bin/bash
#SQOOP_HOME=/opt/cloudera/parcels/CDH-6.2.1-1.cdh6.2.1.p0.1425774/bin/sqoop
SQOOP_HOME=/usr/bin/sqoop
if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

echo '========================================'
echo '==============开始增量导入==============='
echo '========================================'

# ========== 全量 ==========

# 1. 客户关系表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from customer_relationship where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table customer_relationship \
-m 100 \
--split-by id
wait

# 2. 员工表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from employee where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table employee \
-m 100 \
--split-by id
wait

# 3. 部门表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from scrm_department where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table scrm_department \
-m 100 \
--split-by id
wait

# 4. 报名课程表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from itcast_clazz where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table itcast_clazz \
-m 100 \
--split-by id
wait
# 5.客户线索表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *,'${TD_DATE}' as dt from customer_clue where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table customer_clue \
--split-by id \
--m 100
wait

# 6.线索投诉表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query 'select `id`,`customer_relationship_first_id`,`employee_id`,`employee_name`,`employee_department_id`,`employee_tdepart_id`,`appeal_status`,`audit_id`,`audit_name`,`audit_department_id`,`audit_department_name`,`audit_date_time`,`create_date_time`,`update_date_time`,`deleted`,`tenant`,'${TD_DATE}' as dt from customer_appeal where $CONDITIONS' \
--hcatalog-database notp_ods \
--hcatalog-table customer_appeal \
--split-by id \
--m 100
wait

echo '========================================'
echo '=================success==============='
echo '========================================'